#if 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/prctl.h>
#include <sys/select.h>


#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#include "sample_comm.h"



pthread_mutex_t mutex;
pthread_cond_t cond;

char buff[1024];

#if 0
void * func(void * arg)
{
    while(1)
    {
        pthread_mutex_lock(&mutex);
        pthread_cond_wait(&cond, &mutex);

        fprintf(stderr, "print:%s\n", buff);
        memset(buff, 0, sizeof(buff));

        pthread_mutex_unlock(&mutex);
    }

    pthread_exit(NULL);
}
#endif 

void * serverSnap(void * arg)
{
    int fd ;
    int ret = -1;
    fd_set myset;
    struct sockaddr_in server_addr;
    struct sockaddr_in client_addr;
    
#if 0
    pthread_attr_t attr;
    pthread_t th = -1;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    pthread_mutex_init(&mutex, NULL);
    pthread_cond_init(&cond, NULL);

    ret = pthread_create(&th, &attr, func, NULL);
    if(ret != 0)
    {
        printf("pthread_create fail.\n");
        exit(-1);
    }

#endif
    fd = socket(AF_INET, SOCK_STREAM, 0);
    if(fd == -1)
    {
        perror("socket");
        exit(-1);
    }

    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(8554);
    server_addr.sin_addr.s_addr =inet_addr("192.168.1.100");
    bzero(server_addr.sin_zero,8);
    
    bind(fd,(struct sockaddr*)&server_addr,sizeof(server_addr));

    listen(fd,5);

    socklen_t client_addr_size = sizeof(client_addr);
    int cln_sock = accept(fd,(struct sockaddr*)&client_addr,&client_addr_size);
    if(cln_sock < 0)
    {
        fprintf(stderr, "accep fail.\n" );
        exit(-1);
    }
    fprintf(stderr, "accep success.\n" );


    FD_ZERO(&myset);
    FD_SET(cln_sock, &myset);
    
    while(1)
    {   

        ret = select(cln_sock+1, &myset, NULL, NULL, NULL);
        if(ret < 0)
        {
            printf("select fail.\n");
            exit(-1);
        }
        else
        {   if(FD_ISSET(cln_sock, &myset))
            {
                recv(cln_sock, buff, sizeof(buff), 0);
                fprintf(stderr, "%s\n", buff);
                pthread_cond_signal(&cond);   
            }
           
        }
    }

    close(cln_sock);
    close(fd);
    
    return 0;
}



#endif